
//---------------------------------------------------??????????javascript
function menuInit()
{
	if(null!=document.all('nowUserName'))
		document.all('nowUserName').innerHTML= userArray[GetCacheUserID];
	var menuNum = GetCookie("menu")==null?0:GetCookie("menu");
	for(i=0;i<8;i++){
		if(i!=menuNum && null!=document.all('menu_'+i))
			document.all('menu_'+i).style.display = 'none'; //'inline'
	}
}

function GetPrjName()
{
  var tmp = GetCookie("prjInfo").split("|");
  if(tmp.length>0)
  		return tmp[1];
  return null;
}

function GetShowPrjName()
{
  var tmp = GetCookie("ShowPrjInfo").split("|");
  if(tmp.length>0)
  		return tmp[1];
  return null;
}

function href(url)
{
	window.location.href=url;
}

function succeed()
{
	alert('??????????!');
}

function setBColor(obj,url)
{
	var dd = document.getElementById('dataGrid');

	for(var i=0;i<dd.rows.length;i++)
	{
		if(dd.rows[i].style.backgroundColor=='#009999')
		{
			if(i%2==0)
			{
				dd.rows[i].style.backgroundColor='#E8F4FF';

				dd.rows[i].style.color='black';
			}
			else
			{
				dd.rows[i].style.backgroundColor='white';

				dd.rows[i].style.color='black';
			}
		}
	}

	obj.style.backgroundColor = "#009999";

	obj.style.color="#CCFF99";
	window.parent.Detail.document.location.href=url;
	window.parent.More.document.location.href='More0.html';
}

function onSelectRow(obj,url,type)
{
	var dd = document.getElementById('dataGrid');

	for(var i=0;i<dd.rows.length;i++)
	{
		if(dd.rows[i].style.backgroundColor=='#009999')
		{
			if(i%2==0)
			{
				dd.rows[i].style.backgroundColor='#E8F4FF';

				dd.rows[i].style.color='black';
			}
			else
			{
				dd.rows[i].style.backgroundColor='white';

				dd.rows[i].style.color='black';
			}
		}
	}
	obj.style.backgroundColor = "#009999";
	obj.style.color="#CCFF99";

	if(url!=null&&url!='')
	{
		if(type==2)
		{
			window.parent.Detail.document.location.href=url;
			if(window.parent.moreDetail != null)
			{
				window.parent.moreDetail.document.location.href='../share/blank.htm';
				//window.parent.listDetailFrm.rows="40%,60%,*";
			}
		}
		else if(type==3)
		{
			window.parent.moreDetail.document.location.href=url;
			if(initZoom)
				window.parent.listDetailFrm.rows="30%,40%,*";
			else
				window.parent.listDetailFrm.rows="10%,*,35%";
		}
	}
}

function selectPrj()
{
	var prj = window.showModalDialog("common/prjTree.html", "","dialogWidth:530px; dialogHeight:500px;status:No; ");
	if(prj!=null && prj!='undefined')
	{
		SetCookie('prjInfo',prj);
		window.parent.mainFrame.location.reload();
	}
}

function setPrjInfo(info)
{
		var prjVar = info.split('|');
		if(prjVar.length>0)
		{
			document.all('prjCode').innerHTML=prjVar[0];
			document.all('prjName').innerHTML=prjVar[1];
		}
}

function reSetZoom(rowsValue)
{
	if(window.parent.listDetailFrm != null)
		window.parent.listDetailFrm.rows=rowsValue;
}

function zoomOne() //??????????
{
	window.parent.listDetailFrm.rows="80%,10%,*";
}

function zoomTwo() //??????????
{
	window.parent.listDetailFrm.rows="20%,60%,*";
}
function zoomInit() //????????
{
	window.parent.listDetailFrm.rows="50%,40%,*";
}

function pHref(url)
{
	window.parent.location.href=url;
}


function dialogBox(url,w,h)
{
	return window.showModalDialog(url, "","dialogWidth:"+w+"px; dialogHeight:"+h+"px;status:No;scroll:no;resizable:yes;");
}

function noClk()
{
	window.event.cancelBubble = true;
	//window.event.stopPropagation = true;
}

// ------1-------------------------------------------------------
function  crl_ondblclick(img_path)
{
	var tmp = window.parent;
	var i=0;
	while(i<10 && tmp.frameset2==null && tmp.parent!=null)
	{
		tmp = tmp.parent;
		i++;
	}
	if(tmp.frameset2!=null)
		SetCols(tmp.frameset2,img_path);
}

function SetCols(obj,img_path)
{
	var leftNum = "28,*",rightNum = "160,*";
	if(obj.cols == leftNum)
	{
		obj.cols = rightNum;
		document.all('menu_img').src=img_path+'bearLeft.gif';
	}
	else if(obj.cols == rightNum)
	{
		obj.cols = leftNum;
		document.all('menu_img').src=img_path+'bearRight.gif';
	}
	else
	{
		obj.cols = rightNum;
		document.all('menu_img').src=img_path+'bearLeft.gif';
	}
}

function UpDown(img_path)
{
	var tmp = window.parent;
	while(tmp.listDetailFrm==null && tmp.parent!=null)
		tmp = tmp.parent;
	if(tmp.list!=null)
		SetRows(tmp.listDetailFrm,img_path);
}

function ondbl_UpDown(img_path)
{
	var tmp = window.parent;
	while(tmp.listDetailFrm==null && tmp.parent!=null)
		tmp = tmp.parent;
	if(tmp.list!=null)
		tmp.listDetailFrm.rows = "95%,*";
}


function SetRows(obj,img_path)
{
	var upNum = "43,*",downNum = "55%,*";
	if(obj.rows == upNum)
	{
		obj.rows = downNum;
		document.all('img_updown').src=img_path+'Image/bearUp.gif';
	}
	else if(obj.rows == downNum)
	{
		obj.rows = upNum;
		document.all('img_updown').src=img_path+'Image/bearDown.gif';
	}
	else
	{
		obj.rows = downNum;
		document.all('img_updown').src=img_path+'Image/bearUp.gif';
	}
}

function removeHTML(strHTML)
{
	var reg = new RegExp('<.+?>');
	var arr;
	while((arr = reg.exec(strHTML)) != null)
		strHTML = strHTML.replace(arr,'');
	return strHTML;
}

function selectPage(rootPath,pageUrl,w,h,keyObj,showObj,showNum)
{
	var val = dialogBoxEx(rootPath,pageUrl,w,h);
	//var val = dialogBox(pageUrl,w,h);
	if(val != null)
	{
		var ar = val.split("|");
		if(ar.length>0 && ar.length>=showNum)
		{
			if(keyObj!=''&&document.all(keyObj)!=null)
				document.all(keyObj).value = ar[0];
			if(showObj!=''&&document.all(showObj)!=null)
				document.all(showObj).value = ar[showNum];
		}
		else
		{
			alert('????????');
		}
	}
}

function dialogBoxEx(rootPath,pageUrl,w,h)
{
  return window.showModalDialog(rootPath+"common/dialogBox.aspx?url=../"+pageUrl, "","dialogWidth:"+w+"px; dialogHeight:"+h+"px;status:No;scroll:no;resizable:yes;");
}

function viewPage(pageUrl,w,h)
{
	return dialogBox(pageUrl,w,h);
}

String.prototype.trim = function()
{
	return this.replace(/(^\s+)|\s+$/g,"");
}

function initSelect(obj,val)
{
	for(num=0;num<obj.length;num++){
		if(val.trim() == obj.options[num].value){
			obj.options[num].selected = true;
			break;
		}
	}
}

function dialogBoxPrint(preview)
{
	var win = window.open('../admin/print.aspx','dialogboxPrint','toolbar=no,location=no,status=yes,menubar=no,scrollbars=auto,resizable=yes');
	var content = document.body.innerHTML.replace(document.all('td_print_tool').innerHTML,'');
	var obj = null;
	obj = win.document.all('print_content');
	while(obj==null)
		obj = win.document.all('print_content');
	win.document.all('print_content').innerHTML = content;
	win.focus();
	if(preview){
		win.document.all('btn_print_preview').click();
	}
	else{
		win.document.all('btn_print').click();
	}
}

function getYearEx(add_value)
{
	var _year = (new Date()).getYear();
	return _year+add_value;
}

function adv_format(value,num)   //????????
{
    var a_str = formatnumber(value,num);
    var a_int = parseFloat(a_str);
    if (value.toString().length>a_str.length){
        var b_str = value.toString().substring(a_str.length,a_str.length+1)
        var b_int = parseFloat(b_str);
        if (b_int<5){
            return a_str
        }
        else{
            var bonus_str,bonus_int;
            if (num==0){
                bonus_int = 1;
            }
            else{
                bonus_str = "0."
                for (var i=1; i<num; i++)
                    bonus_str+="0";
                bonus_str+="1";
                bonus_int = parseFloat(bonus_str);
            }
            a_str = formatnumber(a_int + bonus_int, num)
        }
    }
    return a_str
}

var initZoom = true;
function reSetZoomEx() {
	if(initZoom)
	{
		reSetZoom('*,100%,*');
		initZoom = false;
	}
	else
	{
		reSetZoom('40%,60%,*');
		initZoom = true;
	}			
}

function formatnumber(value,num)    //????????
{
    var a,b,c,i
    a = value.toString();
    b = a.indexOf('.');
    c = a.length;
    if (num==0){
        if (b!=-1)
            a = a.substring(0,b);
    }
    else{
        if (b==-1){
            a = a + ".";
            for (i=1;i<=num;i++)
                a = a + "0";
        }
        else{
            a = a.substring(0,b+num+1);
            for (i=c;i<=b+num;i++)
                a = a + "0";
        }
    }
    return a
}

function checkAll(chkName, flgChecked)

{
	if(document.all(chkName)){
		var max = document.all(chkName).length;
		if(max!=null)
			for (var idx = 0; idx < max; idx++)
				document.all(chkName)[idx].checked=flgChecked;
	}
}

function revCheck(chkName)

{
	if(document.all(chkName)){
		var max = document.all(chkName).length;
		if(max!=null)
			for (var idx = 0; idx < max; idx++) 
				document.all(chkName)[idx].checked=(!document.all(chkName)[idx].checked);
	}
}

//????????
// sum_row=????????????????????????????????
function sum_table(tbl,chkName,start_row,start_cell,sum_row)
{
  var o = document.getElementById(tbl);//????????????
  if (!o||!document.all(chkName))return;//??????????????????????
  var max = document.all(chkName).length;  
  var ar = new Array();
  
  if(document.all(chkName).checked)
    max = 1;
  if(max!=null){
    var _obj;
    for (var idx = 0; idx < max; idx++)
    {
      if(max==1)
        _obj = document.all(chkName);
      else
        _obj = document.all(chkName)[idx];        
      if(_obj.checked)
      {
        var _td = _obj.parentElement;
        for(n=_td.parentElement.rowIndex;n<_td.parentElement.rowIndex+_td.rowSpan;n++)
        {
          ar.push(n);
        }
      }
    }
  }
  if(2 > ar.length)
  {
    var _tr = o.rows[o.rows.length-sum_row];
    if(_tr!=null){
      for(n=0;n<_tr.cells.length;n++)
        _tr.cells[n].innerHTML='';
      _tr.style.height=0;
    }
    return;
  }
  var cell_num = o.rows[0].cells.length; //????????????????
  var td_rowSpan,td_obj;
  for(i=start_cell;i<cell_num;i++)
  {
    var total=0.0;//??????
    for(j=0;j<ar.length;j++)
    {
      // -----
      td_obj = document.all('xy_'+ar[j]+'_'+i);      
      if(td_obj!=null)
      {
        var t = td_obj.innerText;
        if (t!=null && t.length!= 0 && !isNaN(t))      
          total += parseFloat(t);//??????????
      }
      // -----
      /*
      if(o.rows[ar[j]].cells[i]!=null)
      {
        var t = o.rows[ar[j]].cells[i].innerText;
        if (t.length!= 0 && !isNaN(t))
          total += parseFloat(t);//??????????
      }
      */
    }
    // -----------
    if(total!=0.0 && document.all('td_xy_'+i)!=null)
      document.all('td_xy_'+i).innerHTML = '= '+total;
    // -----------
    /*
    if(total!=0.0 && o.rows[o.rows.length-sum_row].cells[i]!=null)
      o.rows[o.rows.length-sum_row].cells[i].innerHTML = '= '+total;
    */
  }
}
// ---------------------------------

function record_tr_innerText(tr_id,hid_tr_id,start_cell,splitStr)
{
  var tr = document.all(tr_id);  
  var o_tr = document.all(hid_tr_id);
  if(o_tr.value=='')
  {
    var _str="";
    for(i=start_cell;i<tr.cells.length;i++)
	  {
	    if(_str!="")
	      _str+=splitStr;
 		  _str+=removeHTML(tr.cells[i].innerText);
	  }	
	  o_tr.value=_str;
	}	
}  
     
function genTable(sel_tr_id,start_cell,splitStr,initStr)
{
	var strtbl = "";
	var tr_innerText = document.all(sel_tr_id).value;
	if(tr_innerText==null||tr_innerText=='')
	  return '';
	var sel_hid_num = 0
	if(initStr.length>0)
	  sel_hid_num=initStr.split(',').length;
	strtbl = "<table border='1' width='100%' id='frmtbl' bgcolor='#FFFFEE' cellspacing='0' cellpadding='2'>";
	strtbl += "<tr class='tr_Title'><td><input type='checkbox' id='chkAll' name='chkAll' onclick=\"checkAll('sle_cell',this.checked);\" title='????/????'> [<b>??????</b>]</td></tr>";	
	var ar = tr_innerText.split(splitStr);
	for(i=0;i<ar.length;i++){
 		strtbl += "<tr><td nowrap><input type='checkbox' name='sle_cell' value='"+(i+start_cell)+"'";
 	  if(initStr==''||(","+initStr+",").indexOf(","+(i+start_cell)+",")>=0)
 			  strtbl += "checked";
 		strtbl += "/>"+ar[i]+"</td></tr>";
	}  	
	strtbl += "</table>";
	return strtbl;
}

function add_cooperant()
{
    var rv = window.showModalDialog("../common/getCooperant.aspx?selectType=multipleEx","","dialogWidth:650px;dialogHeight:500px;status:No;scroll:yes;resizable:yes;");
    if(rv!=null && rv.length!=null && rv.length>0){
      var idx = [0,2,5,6,7,8];
      var tb = document.all('tb_cooperant');
      for(j=0;j<rv.length;j++)
      {
          var ar = rv[j];
          var newRow = tb.insertRow(tb.rows.length-1);
          var newCell = newRow.insertCell();	
				  newCell.appendChild(document.createElement("<input name='hid_cooperant_id' type='hidden' value='"+ar[0]+"'>"));
          for(i=1;i<tb.rows[0].cells.length-1;i++)
          {
			        newCell= newRow.insertCell();
				      newCell.innerText=ar[idx[i]]+' ';
          }
          newCell = newRow.insertCell();
          newCell.align="center";
			    newCell.appendChild(document.createElement("<input type='button' value='-'  title='????????' style='height:18px' onClick='del_cooperant(this);'>"));
		}
	}
}

function del_cooperant(_obj)
{
  _obj.parentElement.parentElement.removeNode(true);
}

function selectEx(){
  var check = document.all('chk_id');
  var rv = new Array();
  var ar = new Array(9);
  var _obj;
  if(check.checked)
  {
    _obj = check.parentElement.parentElement;
    ar[0] = check.value;
    for(i=1;i<_obj.cells.length;i++)
	    ar[i]=removeHTML(_obj.cells[i].innerText);
    rv.push(ar);
  }
  else if(check.length!=null)
  {
    for (var idx=0;idx<check.length;idx++){
      _obj = check[idx];       
      if(_obj.checked){
        var ar = new Array(9); 
        ar[0] = _obj.value;
        _obj = _obj.parentElement.parentElement;
        for(i=1;i<_obj.cells.length;i++)
	        ar[i]=removeHTML(_obj.cells[i].innerText);	  
        rv.push(ar);
      }
    }  
  }
  if(rv.length>0)
  {
    window.returnValue=rv;
    window.close(true);
   }
   else
    alert('??????????????!');
}

// ??????????????????????????????????????????????????????-??????????
function unite(obj)
{
  var is_break = false;
  for(i=0;i<obj.options.length;i++)
  {
    if(obj.options[i].innerText.indexOf("????")>=0 && obj.options[i].innerText.indexOf("????")>=0)
    {
      obj.options[i].innerText = obj.options[i].innerText.replace("????","????????");
      if(is_break)
        break;
      else
        is_break = true;             
    }
    if(obj.options[i].innerText.indexOf("????")>=0 && obj.options[i].innerText.indexOf("????")==-1 && obj.options[i].innerText.indexOf("????")>=0)
    {         
      obj.remove(i);
      if(is_break)
        break;
      else
        is_break = true;
    }
  }
}

//<!-- Begin
function doit() {
form.input.value = eval(form.input.value)
}
function Cos() {
x = form.input.value
if (x == '') alert('Error: Input Required');
else form.input.value = Math.cos(x);
}
function Sin() {
x = form.input.value
if (x == '') alert('Error: Input Required');
else form.input.value = Math.sin(x);
}
function Ln() {
x = form.input.value
if (x == '') alert('Error: Input Required');
else form.input.value = Math.log(x);
}
function Root() {
x = form.input.value
if (x == '') alert('Error: Input Required');
else form.input.value = Math.sqrt(x);
}
function Tan() {
x = form.input.value
if (x == '') alert('Error: Input Required');
else form.input.value = Math.tan(x);
}
function Icos() {
x = form.input.value
if (x == '') alert('Error: Input Required');
else form.input.value = Math.acos(x);
}
function Isin() {
x = form.input.value
if (x == '') alert('Error: Input Required');
else form.input.value = Math.asin(x);
}
function Itan() {
x = form.input.value
if (x == '') alert('Error: Input Required');
else form.input.value = Math.atan(x);
}
function Round() {
x = form.input.value
if (x == '') alert('Error: Input Required');
else form.input.value = Math.round(x);
}
function Ran() {
x = form.input.value
form.input.value = Math.random(x);
}
function Neg () {
x = form.input.value
if (x == '') alert('Error: Input Required');
else x = parseFloat(x) * -1;
}
function del() {
x = form.input.value
x = (x.substring) - 1
}
//  End -->
// -----------------------------------
    

function changeIndex(me){
  if(changeIndex.top)
 changeIndex.top.style.zIndex="";
  me.style.zIndex=500;
  changeIndex.top=me;
  }
  
  
function neverDragDivision(fObj) 
{ 
 with (this){ if (!fObj) return; this.bDraged = false; 
 this.oDragOrig = fObj; oDragOrig.style.cursor = "move";
 oDragOrig.onmousedown = function() 
 {
  var ofs = Offset(oDragOrig);    
  oDragOrig.style.position = "absolute";  
  oDragOrig.style.left = ofs.l;  
  oDragOrig.style.top = ofs.t;  
  oDragOrig.X = event.clientX - ofs.l;  
  oDragOrig.Y = event.clientY - ofs.t;  
  bDraged = true;
 };   
  oDragOrig.onmousemove = function() 
 {  
  if (!bDraged) return;    
  oDragOrig.setCapture();  
  oDragOrig.style.left = event.clientX - oDragOrig.X;  
  oDragOrig.style.top = event.clientY - oDragOrig.Y; 
 }; 
  oDragOrig.onmouseup = function() 
 {  
  bDraged = false;  
  oDragOrig.releaseCapture(); }; 
  function Offset(e) 
 {  
  var t = e.offsetTop;  
  var l = e.offsetLeft;  
  var w = e.offsetWidth;  
  var h = e.offsetHeight;  
  while(e=e.offsetParent) 
  {   
   t+=e.offsetTop;   
   l+=e.offsetLeft;  
  }  
  return { t:t, l:l, w:w, h:h } 
 };
 }
 };
 
 